﻿using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using System.Data;
using LibHuman;

namespace Human
{
	public class frmbc_chamcongthuongtruc : System.Windows.Forms.Form
	{
		private AccessData mDB =new AccessData();
        Language lan = new Language();
        private DataSet ds = new DataSet();
        private DataSet ds_nv = new DataSet();
        private DataSet ds_ngayle = new DataSet();
        private DataSet ds_ngaybule = new DataSet();
        private DataSet ds_dmqd = new DataSet();
		private System.Windows.Forms.Label label1;
		private System.Windows.Forms.Label label2;
		private System.Windows.Forms.Button btn_xem;
		private System.Windows.Forms.Button btn_thoat;
		private System.Windows.Forms.TextBox txtthang;
		private System.Windows.Forms.TextBox txtnam;
		private string user_dn="", ngay_ht="",thang="",nam="",s_mmyy="",sql2="",sql="",denngay="",tungay="",ngay="",s_bophan=""
            , s_mmyy1 = "", s_ncuoithang = "";
        bool bvantay = false;
		private System.Windows.Forms.Label label3;
		private System.Windows.Forms.ComboBox cbobophan;
		private System.Windows.Forms.GroupBox groupBox1;
		private System.Windows.Forms.RadioButton radBC;
		private System.Windows.Forms.RadioButton radKhac;
        private Button btnexel;
		private System.ComponentModel.Container components = null;

		public frmbc_chamcongthuongtruc(string s_makp,string s_userdn)
		{
			InitializeComponent();
            lan.Read_Language_to_Xml(this.Name.ToString(), this);
            lan.Changelanguage_to_English(this.Name.ToString(), this);
            s_bophan = s_makp;
            user_dn = s_userdn;
		}
		protected override void Dispose( bool disposing )
		{
			if( disposing )
			{
				if(components != null)
				{
					components.Dispose();
				}
			}
			base.Dispose( disposing );
		}

		#region Windows Form Designer generated code
		/// <summary>
		/// Required method for Designer support - do not modify
		/// the contents of this method with the code editor.
		/// </summary>
		private void InitializeComponent()
		{
            System.ComponentModel.ComponentResourceManager resources = new System.ComponentModel.ComponentResourceManager(typeof(frmbc_chamcongthuongtruc));
            this.label1 = new System.Windows.Forms.Label();
            this.label2 = new System.Windows.Forms.Label();
            this.btn_xem = new System.Windows.Forms.Button();
            this.btn_thoat = new System.Windows.Forms.Button();
            this.txtthang = new System.Windows.Forms.TextBox();
            this.txtnam = new System.Windows.Forms.TextBox();
            this.label3 = new System.Windows.Forms.Label();
            this.cbobophan = new System.Windows.Forms.ComboBox();
            this.groupBox1 = new System.Windows.Forms.GroupBox();
            this.radKhac = new System.Windows.Forms.RadioButton();
            this.radBC = new System.Windows.Forms.RadioButton();
            this.btnexel = new System.Windows.Forms.Button();
            this.groupBox1.SuspendLayout();
            this.SuspendLayout();
            // 
            // label1
            // 
            this.label1.Font = new System.Drawing.Font("Microsoft Sans Serif", 9.25F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
            this.label1.ForeColor = System.Drawing.Color.DarkBlue;
            this.label1.Location = new System.Drawing.Point(22, 17);
            this.label1.Name = "label1";
            this.label1.Size = new System.Drawing.Size(56, 23);
            this.label1.TabIndex = 4;
            this.label1.Text = "Tháng :";
            this.label1.TextAlign = System.Drawing.ContentAlignment.MiddleRight;
            // 
            // label2
            // 
            this.label2.Font = new System.Drawing.Font("Microsoft Sans Serif", 9.25F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
            this.label2.ForeColor = System.Drawing.Color.DarkBlue;
            this.label2.Location = new System.Drawing.Point(142, 17);
            this.label2.Name = "label2";
            this.label2.Size = new System.Drawing.Size(40, 23);
            this.label2.TabIndex = 5;
            this.label2.Text = "Năm :";
            this.label2.TextAlign = System.Drawing.ContentAlignment.MiddleRight;
            // 
            // btn_xem
            // 
            this.btn_xem.Font = new System.Drawing.Font("Tahoma", 8.25F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
            this.btn_xem.ForeColor = System.Drawing.Color.DarkBlue;
            this.btn_xem.Image = global::Human.Properties.Resources.t_search;
            this.btn_xem.ImageAlign = System.Drawing.ContentAlignment.MiddleLeft;
            this.btn_xem.Location = new System.Drawing.Point(18, 144);
            this.btn_xem.Name = "btn_xem";
            this.btn_xem.Size = new System.Drawing.Size(60, 28);
            this.btn_xem.TabIndex = 2;
            this.btn_xem.Text = "&Chọn";
            this.btn_xem.TextAlign = System.Drawing.ContentAlignment.MiddleRight;
            this.btn_xem.Click += new System.EventHandler(this.btn_xem_Click);
            // 
            // btn_thoat
            // 
            this.btn_thoat.Font = new System.Drawing.Font("Tahoma", 8.25F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
            this.btn_thoat.ForeColor = System.Drawing.Color.DarkBlue;
            this.btn_thoat.Image = global::Human.Properties.Resources.close_r;
            this.btn_thoat.ImageAlign = System.Drawing.ContentAlignment.MiddleLeft;
            this.btn_thoat.Location = new System.Drawing.Point(166, 144);
            this.btn_thoat.Name = "btn_thoat";
            this.btn_thoat.Size = new System.Drawing.Size(65, 28);
            this.btn_thoat.TabIndex = 3;
            this.btn_thoat.Text = "&Thoát";
            this.btn_thoat.TextAlign = System.Drawing.ContentAlignment.MiddleRight;
            this.btn_thoat.Click += new System.EventHandler(this.btn_thoat_Click);
            // 
            // txtthang
            // 
            this.txtthang.Location = new System.Drawing.Point(84, 17);
            this.txtthang.Name = "txtthang";
            this.txtthang.Size = new System.Drawing.Size(40, 21);
            this.txtthang.TabIndex = 0;
            this.txtthang.Validated += new System.EventHandler(this.txtthang_Validated);
            this.txtthang.KeyDown += new System.Windows.Forms.KeyEventHandler(this.txtthang_KeyDown);
            // 
            // txtnam
            // 
            this.txtnam.Location = new System.Drawing.Point(190, 17);
            this.txtnam.Name = "txtnam";
            this.txtnam.Size = new System.Drawing.Size(56, 21);
            this.txtnam.TabIndex = 1;
            this.txtnam.Validated += new System.EventHandler(this.txtnam_Validated);
            this.txtnam.KeyDown += new System.Windows.Forms.KeyEventHandler(this.txtnam_KeyDown);
            // 
            // label3
            // 
            this.label3.Font = new System.Drawing.Font("Microsoft Sans Serif", 9.25F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
            this.label3.ForeColor = System.Drawing.Color.DarkBlue;
            this.label3.Location = new System.Drawing.Point(10, 51);
            this.label3.Name = "label3";
            this.label3.Size = new System.Drawing.Size(68, 23);
            this.label3.TabIndex = 6;
            this.label3.Text = "Bộ phận :";
            this.label3.TextAlign = System.Drawing.ContentAlignment.MiddleRight;
            // 
            // cbobophan
            // 
            this.cbobophan.Font = new System.Drawing.Font("Tahoma", 9F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
            this.cbobophan.ForeColor = System.Drawing.Color.Navy;
            this.cbobophan.Location = new System.Drawing.Point(84, 53);
            this.cbobophan.Name = "cbobophan";
            this.cbobophan.Size = new System.Drawing.Size(162, 22);
            this.cbobophan.TabIndex = 7;
            this.cbobophan.SelectedIndexChanged += new System.EventHandler(this.cbobophan_SelectedIndexChanged);
            this.cbobophan.TextChanged += new System.EventHandler(this.cbobophan_TextChanged);
            // 
            // groupBox1
            // 
            this.groupBox1.Controls.Add(this.radKhac);
            this.groupBox1.Controls.Add(this.radBC);
            this.groupBox1.Location = new System.Drawing.Point(18, 86);
            this.groupBox1.Name = "groupBox1";
            this.groupBox1.Size = new System.Drawing.Size(233, 47);
            this.groupBox1.TabIndex = 8;
            this.groupBox1.TabStop = false;
            // 
            // radKhac
            // 
            this.radKhac.Font = new System.Drawing.Font("Microsoft Sans Serif", 9.25F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
            this.radKhac.ForeColor = System.Drawing.Color.DarkBlue;
            this.radKhac.Location = new System.Drawing.Point(102, 14);
            this.radKhac.Name = "radKhac";
            this.radKhac.Size = new System.Drawing.Size(120, 24);
            this.radKhac.TabIndex = 1;
            this.radKhac.Text = "Không biên chế";
            // 
            // radBC
            // 
            this.radBC.Font = new System.Drawing.Font("Microsoft Sans Serif", 9.25F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
            this.radBC.ForeColor = System.Drawing.Color.DarkBlue;
            this.radBC.Location = new System.Drawing.Point(14, 11);
            this.radBC.Name = "radBC";
            this.radBC.Size = new System.Drawing.Size(82, 24);
            this.radBC.TabIndex = 0;
            this.radBC.Text = "Biên chế";
            // 
            // btnexel
            // 
            this.btnexel.Font = new System.Drawing.Font("Tahoma", 8.25F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
            this.btnexel.ForeColor = System.Drawing.Color.DarkBlue;
            this.btnexel.Image = global::Human.Properties.Resources.white_excel;
            this.btnexel.ImageAlign = System.Drawing.ContentAlignment.MiddleLeft;
            this.btnexel.Location = new System.Drawing.Point(91, 144);
            this.btnexel.Name = "btnexel";
            this.btnexel.Size = new System.Drawing.Size(60, 28);
            this.btnexel.TabIndex = 9;
            this.btnexel.Text = "&Excel";
            this.btnexel.TextAlign = System.Drawing.ContentAlignment.MiddleRight;
            this.btnexel.Click += new System.EventHandler(this.btnexel_Click);
            // 
            // frmbc_chamcongthuongtruc
            // 
            this.AutoScaleBaseSize = new System.Drawing.Size(5, 14);
            this.ClientSize = new System.Drawing.Size(263, 184);
            this.Controls.Add(this.btnexel);
            this.Controls.Add(this.groupBox1);
            this.Controls.Add(this.cbobophan);
            this.Controls.Add(this.label3);
            this.Controls.Add(this.txtnam);
            this.Controls.Add(this.txtthang);
            this.Controls.Add(this.btn_thoat);
            this.Controls.Add(this.btn_xem);
            this.Controls.Add(this.label2);
            this.Controls.Add(this.label1);
            this.Font = new System.Drawing.Font("Tahoma", 8.25F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
            this.ForeColor = System.Drawing.Color.Navy;
            this.Icon = ((System.Drawing.Icon)(resources.GetObject("$this.Icon")));
            this.Name = "frmbc_chamcongthuongtruc";
            this.ShowInTaskbar = false;
            this.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen;
            this.Text = "Báo cáo chấm công";
            this.Load += new System.EventHandler(this.frmbc_chamcongthuongtruc_Load);
            this.groupBox1.ResumeLayout(false);
            this.ResumeLayout(false);
            this.PerformLayout();

		}
		#endregion

        private void frmbc_chamcongthuongtruc_Load(object sender, EventArgs e)
        {
            try
            {
                ngay_ht = DateTime.Now.Day.ToString().PadLeft(2, '0');
                txtthang.Text = DateTime.Now.Month.ToString();
                txtnam.Text = DateTime.Now.Year.ToString();
                thang = txtthang.Text.Trim().PadLeft(2, '0');
                nam = txtnam.Text.Trim();
                s_mmyy = thang + nam.Substring(2, 2);
                s_ncuoithang = mDB.get_ncuoithangddmmyyyy(thang,nam);
                DateTime d1 = Convert.ToDateTime(s_ncuoithang.Substring(3, 2) + "/" + s_ncuoithang.Substring(0, 2) + "/" + s_ncuoithang.Substring(6, 4));
                s_mmyy1 = d1.AddMonths(1).ToString("MMyy");
                ngay = mDB.get_ngaytrongthang(thang, nam);
                tungay = "01/" + thang + "/" + nam;
                denngay = ngay + "/" + thang + "/" + nam;
                bvantay = mDB.bVantay(s_mmyy);
                get_dsmaca();
                ds_ngayle = mDB.get_ngaynghile(0, s_mmyy);
                ds_ngaybule = mDB.get_ngaynghile(1, s_mmyy);
                ds_dmqd = mDB.get_nhom_qdcc("TR");
                Load_bophan();
            }
            catch { }
        }

		private void txtthang_KeyDown(object sender, System.Windows.Forms.KeyEventArgs e)
		{
			if(e.KeyCode==Keys.Enter)
				SendKeys.Send("{Tab}");
		}

		private void txtnam_KeyDown(object sender, System.Windows.Forms.KeyEventArgs e)
		{
			if(e.KeyCode==Keys.Enter)
				SendKeys.Send("{Tab}");
		}

		private void Load_bophan()
		{
			cbobophan.DisplayMember="tenbp";
			cbobophan.ValueMember="madv";
			cbobophan.DataSource =mDB.get_bophan().Tables[0];
			cbobophan.SelectedIndex =-1;
		}
		private bool ktra(string a)
		{
			int i=0;
			try
			{
				i =int.Parse(a.Trim());
				return true;
			}
			catch
			{
				return false;
			}
		}
		private bool Kiemtra(string tn)
		{
			try
			{
				DataSet ds =new DataSet();
				ds =mDB.get_data("select * from bcc"+tn+"");
				return ds.Tables[0].Rows.Count>0;
			}
			catch
			{
				return false;
			}
		}
        private void print(int prn)
        {
            DataSet dstmp = new DataSet();
            ExportToExcel exp = new ExportToExcel();
            DataSet ds1=get_data();
            ds1.WriteXml("..\\xml\\h_chamcong_thuongtruc.xml", XmlWriteMode.WriteSchema);
            if (ds1.Tables[0].Rows.Count > 0)
            {
                switch (prn)
                {
                    case 1:frmReport f = new frmReport(mDB, ds1, "", "h_Bangchamcong_thuongtruc.rpt", true, 0,user_dn);
                           f.ShowDialog();
                           break;
                    case 2:dstmp = exp_exel(ds1);
                           exp.exp_excel_ccthuongtruc(dstmp, "bangchamcongthuongtruc_" + s_mmyy, thang, nam);
                           break;
                }					
            }
        }
		private DataSet get_data()
		{
            
            thang = txtthang.Text.Trim().PadLeft(2, '0');
            nam = txtnam.Text.Trim();
            s_mmyy = thang + nam.Substring(2, 2);
            string sql = "", ngay = "", chamcong_tt = "";
            s_mmyy = thang + nam.Substring(2, 2);       
            for (int i = 1; i <= 31; i++)
            {
                ngay = "n" + i.ToString();
                chamcong_tt += " case when trim(upper(" + ngay + ")) <> '' then trim(upper(" + ngay + "))  else '' end as m" + ngay + ", ";
            }            
            sql = " select '" + thang + "' as thang, '" + nam + "' as nam,hd.macv,a.manv,bp.madv,bp.tenbp as bophan,trim(a.ho)||' '||trim(a.ten) as hoten,c.ten,";
            if (radBC.Checked == true)
                sql += " 'Biên chế' as labl,";
            else
                if (radKhac.Checked == true)
                    sql += " 'Ngoài biên chế' as labl,";
                else
                    sql += " ' ' as labl,";
            chamcong_tt = chamcong_tt.Trim();        
            sql += chamcong_tt.Substring(0, chamcong_tt.Length - 1);
            sql += " , 0 as tt,0 as tn,0 as tl,0 as ht,0 as hn,0 as hl,bp.sothutu as stt_bp,cv.stt as stt_cv,c.thutu as stt_cd";
            sql += " from " + mDB.user + ".llnv as a inner join " + mDB.user + ".hopdong as hd on a.manv=hd.manv ";
            sql += " inner join " + mDB.user + ".chamcong_thuongtruc_"+s_mmyy+" as b on a.manv=b.manv";
            sql += " left join " + mDB.user + ".dmcd as c on a.macd=c.ma";
            sql += " left join " + mDB.user + ".bophan as bp on bp.madv=b.madv";
            sql += " inner join " + mDB.user + ".dmcv as cv on hd.macv=cv.macv";
            sql += " inner join "+mDB.user+".mahd mh on hd.loaihd=mh.mahd";
            sql += " inner join " + mDB.user + ".max_lan ml on hd.manv=ml.manv";
            sql += " where hd.ngayhd is not null and b.mmyy='" + s_mmyy + "'";
            sql += " and to_timestamp(hd.ngaydenct,'yyyy-mm-dd') <=to_timestamp('" + nam + "-" + thang + "-" + ngay_ht + "','yyyy-mm-dd')";
            if (cbobophan.SelectedIndex > -1)
            {
                sql += "  and b.madv='" + cbobophan.SelectedValue.ToString().Trim() + "' ";
            }
            if (radBC.Checked == true)
                sql += " and mh.nhombc=1";
            else
                if (radKhac.Checked == true)
                    sql += " and mh.nhombc <> 1";
            sql += " and hd.lan=ml.lan";
            sql += " order by bp.sothutu";
            sql2 = " select * from " + mDB.user + ".dmlydo_phep where nhombc='TR' order by stt";
            ds = mDB.get_data(sql,sql2);
            if (ds.Tables[0].Rows.Count > 0)
            {
                foreach (DataRow dr in ds.Tables[0].Rows)
                {
                    int tt = 0, tn = 0, tl = 0, ht = 0, hn = 0, hl = 0;
                    for (int i = 1; i <= 31; i++)
                    {                        
                        if (dr["mn" + i.ToString() + ""].ToString().Trim().ToUpper() == "TT")
                            tt++;
                        if (dr["mn" + i.ToString() + ""].ToString().Trim().ToUpper() == "TN")
                            tn++;
                        if (dr["mn" + i.ToString() + ""].ToString().Trim().ToUpper() == "TL")
                            tl++;
                        if (dr["mn" + i.ToString() + ""].ToString().Trim().ToUpper() == "HT")
                            ht++;
                        if (dr["mn" + i.ToString() + ""].ToString().Trim().ToUpper() == "HN")
                            hn++;
                        if (dr["mn" + i.ToString() + ""].ToString().Trim().ToUpper() == "HL")
                            hl++;
                        string str = dr["mn" + i.ToString() + ""].ToString();
                        if (str.Trim() != "")
                        {
                            DataRow[] r = ds.Tables[1].Select("ma = '" + str.Trim() + "' ");
                            if (r.Length > 0)
                            {
                                dr["mn" + i.ToString() + ""] = r[0]["kihieu_phep"].ToString();
                            }
                            else
                            {
                                dr["mn" + i.ToString() + ""] = "";
                            }
                        }
                        else
                        {
                            dr["mn" + i.ToString() + ""] = "";
                        }
                    }
                    dr["tt"] = tt.ToString();
                    dr["tn"] = tn.ToString();
                    dr["tl"] = tl.ToString();
                    dr["ht"] = ht.ToString();
                    dr["hn"] = hn.ToString();
                    dr["hl"] = hl.ToString();
                }
            }
            else
            {
                MessageBox.Show(lan.Change_language_MessageText("Chưa có dữ liệu"),lan.Change_language_MessageText("Thông báo"),MessageBoxButtons.OK,MessageBoxIcon.Warning);
            }
            return ds;
		}        
        private DataSet exp_exel(DataSet dse)
        {
            DataSet dse1 = new DataSet();
            dse1.Tables.Add();
            dse1.Tables[0].Columns.Add("stt", typeof(string));
            dse1.Tables[0].Columns.Add("Hoten", typeof(string));         
            string []ngay=new string[] {"01", "02", "03", "04", "05", "06", "07", "08", "09", "10", "11", "12", "13", "14", "15", "16", "17", "18", "19","20", "21", "22", "23", "24", "25", "26", "27", "28", "29", "30", "31"};
            for(int i=0;i<ngay.Length;i++)
            {
                dse1.Tables[0].Columns.Add(ngay[i], typeof(string));
            }                        
            dse1.Tables[0].Columns.Add("TT", typeof(string));
            dse1.Tables[0].Columns.Add("TN", typeof(string));
            dse1.Tables[0].Columns.Add("TL", typeof(string));
            dse1.Tables[0].Columns.Add("HT", typeof(string));
            dse1.Tables[0].Columns.Add("HN", typeof(string));
            dse1.Tables[0].Columns.Add("HL", typeof(string));           

            int stt = 0;
            DataRow nrow;
            foreach (DataRow r in dse.Tables[0].Rows)
            {
                stt++;
                nrow = dse1.Tables[0].NewRow();
                nrow["stt"] = stt;
                nrow["Hoten"] = r["Hoten"].ToString();
                for (int i = 1; i <= 31; i++)
                {
                    string n = i.ToString().PadLeft(2,'0');
                    string m = "mn"+i.ToString();
                    nrow[n] = r[m].ToString();
                }
                nrow["TT"] = r["TT"].ToString();
                nrow["TN"] = r["TN"].ToString();
                nrow["TL"] = r["TL"].ToString();
                nrow["HT"] = r["HT"].ToString();
                nrow["HN"] = r["HN"].ToString();
                nrow["HL"] = r["HL"].ToString();
                dse1.Tables[0].Rows.Add(nrow);
            }
            return dse1;
        }

        private void btnexel_Click(object sender, EventArgs e)
        {
            print(2);
            btn_thoat.Focus();
        }
        #region TONG HOP CHAM CONG VAN TAY THUONG TRUC
        string  f_kh = "";
        string f_hc = "", f_tr = "", f_ng = "", f_tq = "", f_tc = "", f_khac = "", fields_hc = "", fields_tr = "", fields_ng = "", fields_tq = "", fields_tc = "", fields_khac = "";
        int kt_st = 0;//kiem tra ly do di tre ve som
        private void get_dsmaca()
        {
            string sql1 = " select case when manhom='HC' then maca else null end as hc";
            sql1 += " ,case when manhom='TR' then maca else null end as tr";
            sql1 += " ,case when manhom='NG' then maca else null end as ng";
            sql1 += " ,case when manhom='TQ' then maca else null end as tq ";
            sql1 += " ,case when manhom='TC' then maca else null end as tc ";
            sql1 += " ,case when manhom='KH' then maca else null end as kh from " + mDB.user + ".lichlv";
            DataSet ds_ma = mDB.get_data(sql1);

            for (int k = 0; k < ds_ma.Tables[0].Rows.Count; k++)
            {
                if (ds_ma.Tables[0].Rows[k]["hc"].ToString().Trim() != "")
                {
                    f_hc += " '" + ds_ma.Tables[0].Rows[k]["hc"].ToString().Trim() + "',";
                }
                if (ds_ma.Tables[0].Rows[k]["tr"].ToString().Trim() != "")
                {
                    f_tr += " '" + ds_ma.Tables[0].Rows[k]["tr"].ToString().Trim() + "',";
                }
                if (ds_ma.Tables[0].Rows[k]["ng"].ToString().Trim() != "")
                {
                    f_ng += " '" + ds_ma.Tables[0].Rows[k]["ng"].ToString().Trim() + "',";
                }
                if (ds_ma.Tables[0].Rows[k]["tq"].ToString().Trim() != "")
                {
                    f_tq += " '" + ds_ma.Tables[0].Rows[k]["tq"].ToString().Trim() + "',";
                }
                if (ds_ma.Tables[0].Rows[k]["tc"].ToString().Trim() != "")
                {
                    f_tc += " '" + ds_ma.Tables[0].Rows[k]["tc"].ToString().Trim() + "',";
                }
                if (ds_ma.Tables[0].Rows[k]["kh"].ToString().Trim() != "")
                {
                    f_kh += " '" + ds_ma.Tables[0].Rows[k]["kh"].ToString().Trim() + "',";
                }
            }
            // lay danh sach nhom maca 
            fields_hc = f_hc.Length > 0 ? f_hc.Substring(0, f_hc.Length - 1) : "";
            fields_tr = f_tr.Length > 0 ? f_tr.Substring(0, f_tr.Length - 1) : "";
            fields_ng = f_ng.Length > 0 ? f_ng.Substring(0, f_ng.Length - 1) : "";
            fields_tq = f_tq.Length > 0 ? f_tq.Substring(0, f_tq.Length - 1) : "";
            fields_tc = f_tc.Length > 0 ? f_tc.Substring(0, f_tc.Length - 1) : "";
            fields_khac = f_khac.Length > 0 ? f_khac.Substring(0, f_khac.Length - 1) : "";

        }
        private DataSet get_thbcchamcongthang(string mmyy)
        {
            sql = " select distinct nv.manv,trim(nv.ho)||' '||trim(nv.ten) as hoten,nv.madv,bp.tenbp,0.0 as ts_tg,0.0 as ts_om,";
            sql += " 0.0 as ts_co,0.0 as ts_ad,0.0 as ts_bu,0.0 as ts_pn,0.0 as ts_ts,0.0 as ts_kt,0.0 as ts_tn,";
            sql += " 0.0 as ts_hh,0.0 as ts_ct,0.0 as ts_ld,0.0 as ts_dh,0.0 as ts_ot,0.0 as ts_kl,0.0 as ts_kh,0.0 as ts_bl,0.0 as t_cl,";
            sql += " 0.0 as t_kl,0.0 as t_bh,0.0 as t_kh,0.0 as sn_tru,0.0 as sn_cong";
            sql += " ,'' as tsvao_s,'' as tsvao_t";
            sql += " ,'' as n01,'' as n02,";
            sql += " '' as n03,'' as n04,'' as n05,'' as n06,'' as n07,'' as n08,'' as n09,";
            sql += " '' as n10,'' as n11,'' as n12,'' as n13,'' as n14,'' as n15,'' as n16,'' as n17,";
            sql += " '' as n18,'' as n19,'' as n20,'' as n21,'' as n22,'' as n23,'' as n24,'' as n25,";
            sql += " '' as n26,'' as n27,'' as n28,'' as n29,'' as n30,'' as n31";
            sql += " ,'' as tsra_s,'' as tsra_t,'' as ghichu,'' as tsngay_lv";
            sql += " ,0.0 as m1,0.0 as m2,0.0 as m3,0.0 as tongcong";
            sql += " ,'" + mmyy + "' as mmyy,'" + thang + "' as thang,'" + nam + "' as nam";
            sql += " ,0 as tt,0 as tn,0 as tl,0 as ht,0 as hn,0 as hl,0.0 as m4,0.0 as m5,0.0 as m6,0.0 as sntru_tt";//dung cho thuong truc
            sql += " ,0.0 as n_nt,0.0 as n_t7,0.0 as n_lt,0.0 as d_nt,0.0 as d_t7,0.0 as d_lt";
            sql += " from " + mDB.user + ".llnv nv left join " + mDB.user + ".bophan bp on nv.madv=bp.madv";
            sql += " inner join " + mDB.user + ".hopdong hd on nv.manv=hd.manv";
            sql += " inner join " + mDB.user + ".max_lan ml on hd.manv=ml.manv";
            sql += " inner join " + mDB.user + ".mahd mh on hd.loaihd=mh.mahd";
            sql += " inner join " + mDB.user + ".ccvao_" + mmyy + " cv on nv.manv=cv.manv";
            sql += " where hd.lan=ml.lan and (ngaynghi is null or to_timestamp(to_char(ngaynghi,'dd/mm/yyyy'),'dd/mm/yyyy')";
            sql += " > to_timestamp('" + denngay + "','dd/mm/yyyy'))";
            if (fields_tr.Trim() != "")
                sql += " and to_char(cv.maca) in (" + fields_tr.Trim() + ")";
            if (s_bophan.Trim() != "")
                sql += " and nv.madv='" + s_bophan.Trim() + "'";
            if (radBC.Checked == true)
                sql += " and mh.nhombc=1";
            else
                if (radKhac.Checked == true)
                    sql += " and mh.nhombc <> 1";
            sql += " order by nv.manv";
            return mDB.get_data(sql);
        }
        private DataSet get_nvccthuongtruc_vt(string s_mmyy)
        {
            sql = " select l.manv,trim(l.ho)||' '||trim(l.ten) as hoten,l.madv,bp.tenbp,bp.sothutu,cd.ten as chucdanh";
            sql += " ,cv.lydo as lydo_v,cr.lydo as lydo_r,to_char(cv.ngay,'dd/mm/yyyy') as ngaylv";
            sql += " ,cv.somtre as somtre_v,cv.tgsomtre as tgsomtre_v";
            sql += " ,cr.somtre as somtre_r,cr.tgsomtre as tgsomtre_r,to_char(cv.maca) as maca";
            sql += " from " + mDB.user + ".llnv l inner join " + mDB.user + ".hopdong hd on l.manv=hd.manv";
            sql += " inner join " + mDB.user + ".bophan bp on l.madv=bp.madv";
            sql += " left join " + mDB.user + ".ccvao_" + s_mmyy + " cv on l.manv=cv.manv";
            sql += " left join " + mDB.user + ".ccra_" + s_mmyy + " cr on l.manv=cr.manv";
            sql += " left join " + mDB.user + ".dmcd cd on l.macd=cd.ma";
            sql += " inner join " + mDB.user + ".max_lan ml on hd.manv=ml.manv";
            sql += " inner join " + mDB.user + ".mahd mh on hd.loaihd=mh.mahd";
            sql += " where hd.lan=ml.lan and cv.maca=cr.maca and cv.kt_ng=cr.kt_ng";
            sql += " and date_part('day', age(to_timestamp(to_char(cr.ngay,'yyyy-mm-dd'),'yyyy-mm-dd'),to_timestamp(to_char(cv.ngay,'yyyy-mm-dd'),'yyyy-mm-dd')))=1";
            if (fields_tr.Trim() != "")
                sql += " and to_char(cv.maca) in (" + fields_tr.Trim() + ")";
            if (s_bophan.Trim() != "")
                sql += " and l.madv = '" + s_bophan.Trim() + "'";
            if (radBC.Checked == true)
                sql += " and mh.nhombc=1";
            else
                if (radKhac.Checked == true)
                    sql += " and mh.nhombc <> 1";
            if (mDB.bMmyy(s_mmyy1))
            {
                sql += " union";
                sql += " select l.manv,trim(l.ho)||' '||trim(l.ten) as hoten,l.madv,bp.tenbp,bp.sothutu,cd.ten as chucdanh";
                sql += " ,cv.lydo as lydo_v,cr.lydo as lydo_r,to_char(cv.ngay,'dd/mm/yyyy') as ngaylv";
                sql += " ,cv.somtre as somtre_v,cv.tgsomtre as tgsomtre_v";
                sql += " ,cr.somtre as somtre_r,cr.tgsomtre as tgsomtre_r,to_char(cv.maca) as maca";
                sql += " from " + mDB.user + ".llnv l inner join " + mDB.user + ".hopdong hd on l.manv=hd.manv inner join " + mDB.user + ".bophan bp on l.madv=bp.madv";
                sql += " inner join " + mDB.user + ".ccvao_" + s_mmyy + " cv on l.manv=cv.manv";
                sql += " inner join " + mDB.user + ".ccra_" + s_mmyy1 + " cr on cv.manv=cr.manv";
                sql += " left join " + mDB.user + ".dmcd cd on l.macd=cd.ma inner join " + mDB.user + ".max_lan ml on hd.manv=ml.manv";
                sql += " inner join " + mDB.user + ".mahd mh on hd.loaihd=mh.mahd";
                sql += " where hd.lan=ml.lan  and cv.maca=cr.maca and cv.kt_ng=cr.kt_ng";
                sql += " and to_timestamp(to_char(cv.ngay,'dd/MM/yyyy'),'dd/MM/yyyy')=to_timestamp('" + s_ncuoithang.Trim() + "','dd/MM/yyyy')";
                sql += " and date_part('day', age(to_timestamp(to_char(cr.ngay,'yyyy-mm-dd'),'yyyy-mm-dd'),to_timestamp(to_char(cv.ngay,'yyyy-mm-dd'),'yyyy-mm-dd')))=1";
                if (fields_tr.Trim() != "")
                    sql += " and to_char(cv.maca) in (" + fields_tr.Trim() + ")";
                if (s_bophan.Trim() != "")
                    sql += " and l.madv = '" + s_bophan.Trim() + "'";
                if (radBC.Checked == true)
                    sql += " and mh.nhombc=1";
                else
                    if (radKhac.Checked == true)
                        sql += " and mh.nhombc <> 1";
            }
            return mDB.get_data(sql);
        }
        #region kiemtra
        private int kt_khuvuc(string madv)
        {
            string str = mDB.get_madv_theokv("HS");
            int flag = 0;
            string[] arr = str.Split(',');
            for (int i = 0; i < arr.Length; i++)
            {
                if (madv.Trim() == arr[i].ToString().Trim())
                {
                    flag = 1;
                    break;
                }
                else
                {
                    flag = 0;
                }
            }
            return flag;
        }
        private int kt_ngayle(string ngay)
        {
            int flag = 0;
            foreach (DataRow dr in ds_ngayle.Tables[0].Rows)
            {
                if (ngay.Trim() == dr["ngay"].ToString().Trim())
                {
                    flag = 1;
                    break;
                }
                else
                {
                    flag = 0;
                }
            }
            return flag;
        }
        private int kt_ngaybule(string ngay)
        {
            int flag = 0;
            foreach (DataRow dr in ds_ngaybule.Tables[0].Rows)
            {
                if (ngay.Trim() == dr["ngay"].ToString().Trim())
                {
                    flag = 1;
                    break;
                }
                else
                {
                    flag = 0;
                }
            }
            return flag;
        }
        #endregion
        private string get_quydinh(int sophut)
        {
            string kyhieu = "";
            if (ds_dmqd.Tables[0].Rows.Count > 0)
            {
                int tu = 0, den = 0;
                foreach (DataRow dr in ds_dmqd.Tables[0].Rows)
                {
                    tu = int.Parse(dr["tu"].ToString());
                    den = int.Parse(dr["den"].ToString());
                    if (tu <= sophut && den >= sophut)
                    {
                        kyhieu = dr["kyhieu"].ToString();
                        break;
                    }
                }
            }
            return kyhieu;
        }
        private  void print1()
        {
            int kq1 = 0, kq2 = 0, kq3 = 0;
            kq1 = get_solan("M4");
            kq2 = get_solan("M5");
            kq3 = get_solan("M6");
            string mm = "", yyyy = "", s_ngay = "", maca = "";
            mm = txtthang.Text.ToString().PadLeft(2, '0');//thang
            yyyy =txtnam.Text.ToString();
            s_ngay = mDB.get_ngaytrongthang(mm, yyyy).PadLeft(2, '0');
            if (cbobophan.SelectedIndex != -1)
                s_bophan = cbobophan.SelectedValue.ToString().Trim();
            if (mDB.bMmyy(s_mmyy))
            {
                ds_nv = get_thbcchamcongthang(s_mmyy);
                ds = get_nvccthuongtruc_vt(s_mmyy);
            }
            if (ds_nv.Tables[0].Rows.Count > 0)
            {
                string ngay_lv = "", madv = "";
                foreach (DataRow dr_nv in ds_nv.Tables[0].Rows)
                {
                    DataRow[] dr = ds.Tables[0].Select("manv='" + dr_nv["manv"].ToString().Trim() + "'");
                    string s_vao = "", s_ra = "", s_dong = "";
                    string f_ngay = "";
                    int pr_t = 0, pts_vs = 0, pts_vt = 0, pts_rs = 0, pts_rt = 0, m1 = 0, m2 = 0, m3 = 0;
                    int tt = 0, tn = 0, tl = 0, ht = 0, hn = 0, hl = 0;
                    decimal ts_ngaycc = 0, sn_tru = 0, sn_cong = 0;
                    if (dr.Length > 0)
                    {
                        f_ngay = dr[0]["ngaylv"].ToString().Substring(0, 2);
                    }
                    foreach (DataRow r in dr)
                    {
                        int pv_s = 0, pv_t = 0, pr_s = 0;
                        int h_vao = 0, p_vao = 0, h_ra = 0, p_ra = 0;
                        string khieu = "";
                        ngay_lv = r["ngaylv"].ToString();
                        madv = r["madv"].ToString().Trim();
                        DateTime d_ngay = mDB.StringToDate(ngay_lv);
                        if (dr.Length > 0)
                        {
                            f_ngay = dr[0]["ngaylv"].ToString().Substring(0, 2);

                        }
                        if (r["ngaylv"].ToString().Trim() != "")
                        {
                            if (f_ngay != r["ngaylv"].ToString().Substring(0, 2))
                            {
                                f_ngay = r["ngaylv"].ToString().Substring(0, 2);
                                s_dong = ""; s_vao = ""; s_ra = "";
                                //ts_ngaycc += 1;
                            }
                           
                            if (kt_khuvuc(madv) == 1)
                            {
                                if (kt_ngayle(ngay_lv) == 1)
                                {
                                    hl++;
                                }
                                else
                                {
                                    if (kt_ngaybule(ngay_lv) == 1)
                                    {
                                        hn++;
                                    }
                                    else
                                    {
                                        if (mDB.cc_cuoituan(s_mmyy))
                                        {
                                            
                                            if (d_ngay.DayOfWeek == DayOfWeek.Sunday)
                                            {
                                                hn++;
                                            }
                                            else
                                            {
                                                ht++;
                                            }
                                        }
                                        else
                                        {
                                            if (d_ngay.DayOfWeek == DayOfWeek.Saturday || d_ngay.DayOfWeek == DayOfWeek.Sunday)
                                            {
                                                hn++;
                                            }
                                            else
                                            {
                                                ht++;
                                            }
                                        }
                                    }
                                }
                            }
                            else
                            {
                                if (kt_ngayle(ngay_lv) == 1)
                                {
                                    tl++;
                                }
                                else
                                {
                                    if (kt_ngaybule(ngay_lv) == 1)
                                    {
                                        tn++;
                                    }
                                    else
                                    {
                                        if (mDB.cc_cuoituan(s_mmyy))
                                        {
                                            if (d_ngay.DayOfWeek == DayOfWeek.Sunday)
                                            {
                                                tn++;
                                            }
                                            else
                                            {
                                                tt++;
                                            }
                                        }
                                        else
                                        {
                                            if (d_ngay.DayOfWeek == DayOfWeek.Saturday || d_ngay.DayOfWeek == DayOfWeek.Sunday)
                                            {
                                                tn++;
                                            }
                                            else
                                            {
                                                tt++;
                                            }
                                        }
                                    }
                                }
                            }
                            ts_ngaycc += 1;

                            int doirap_v = 0, doirap_r = 0;
                            bool somtre_v = false, somtre_r = false;
                            string ccv = "", ccr = "";
                            ccv = r["tgsomtre_v"].ToString();
                            ccr = r["tgsomtre_r"].ToString();
                            string[] g_vao; string[] g_ra;
                            string manv = r["manv"].ToString().Trim();
                            if (ccv.Trim() != "" && ccr.Trim() != "")
                            {
                                g_vao = ccv.Split(':'); g_ra = ccr.Split(':');
                                h_vao = int.Parse(g_vao[0].ToString());
                                p_vao = int.Parse(g_vao[1].ToString());
                                h_ra = int.Parse(g_ra[0].ToString());
                                p_ra = int.Parse(g_ra[1].ToString());
                            }
                            else
                            {
                                h_vao = 0;
                                p_vao = 0;
                                h_ra = 0;
                                p_ra = 0;
                            }
                            somtre_v = bool.Parse(r["somtre_v"].ToString());
                            somtre_r = bool.Parse(r["somtre_r"].ToString());
                            doirap_v = h_vao * 60 + p_vao;
                            doirap_r = h_ra * 60 + p_ra;
                            DateTime ngay = Convert.ToDateTime(ngay_lv.Substring(3, 3) + ngay_lv.Substring(0, 3) + ngay_lv.Substring(6, 4));
                            if (!somtre_v)
                            {
                                pv_s = doirap_v;
                                pts_vs += pv_s;
                            }
                            if (somtre_v)
                            {
                                pv_t = doirap_v;
                                pts_vt += pv_t;
                            }
                            if (somtre_r)
                            {
                                pr_s = doirap_r;
                                pts_rs += pr_s;
                            }
                            if (!somtre_r)
                            {
                                pr_t = doirap_r;
                                pts_rt += pr_t;
                            }
                            // ky hieu hien thi thoi gian vao
                            if (pv_s > pv_t)
                            {
                                s_vao = "+" + pv_s.ToString().PadLeft(2, '0');
                            }
                            if (pv_s < pv_t)
                            {
                                s_vao = "-" + pv_t.ToString().PadLeft(2, '0');
                                khieu = get_quydinh(pv_t);
                                if (kt_st == 0)
                                {
                                    if (khieu == "M4")
                                    {
                                        m1++;
                                    }
                                    if (khieu == "M5")
                                    {
                                        m2++;
                                    }
                                    if (khieu == "M6")
                                    {
                                        m3++;
                                    }
                                }
                            }
                            if (pv_s == pv_t)
                            {
                                s_vao = pv_t.ToString().PadLeft(2, '0');
                            }
                            // ky hieu hien thi thoi gian ra 
                            if (pr_s > pr_t)
                            {
                                s_ra = "-" + pr_s.ToString().PadLeft(2, '0');
                                khieu = get_quydinh(pr_s);
                                if (kt_st == 0)
                                {
                                    if (khieu == "M4")
                                    {
                                        m1++;
                                    }
                                    if (khieu == "M5")
                                    {
                                        m2++;
                                    }
                                    if (khieu == "M6")
                                    {
                                        m3++;
                                    }
                                }
                            }
                             if (pr_s < pr_t)
                                {
                                    s_ra = "+" + pr_t.ToString().PadLeft(2, '0');
                                }
                                if (pr_s == pr_t)
                                {
                                    s_ra = pr_s.ToString().PadLeft(2, '0');
                                }
                                s_dong += s_vao + ":" + s_ra + " ";
                            }
                            else
                            {
                                s_dong += "  " + r["lydo"].ToString() + " ";
                             
                            }
                            dr_nv["n" + r["ngaylv"].ToString().Substring(0, 2) + ""] = s_dong;
                        }
                    // gan du lieu tong thoi gian vao som tre trong thang cua nhan vien
                    dr_nv["tsvao_s"] = (pts_vs / 60).ToString().PadLeft(2, '0') + ":" + (pts_vs % 60).ToString().PadLeft(2, '0');
                    dr_nv["tsvao_t"] = (pts_vt / 60).ToString().PadLeft(2, '0') + ":" + (pts_vt % 60).ToString().PadLeft(2, '0');
                    dr_nv["tsra_s"] = (pts_rs / 60).ToString().PadLeft(2, '0') + ":" + (pts_rs % 60).ToString().PadLeft(2, '0');
                    dr_nv["tsra_t"] = (pts_rt / 60).ToString().PadLeft(2, '0') + ":" + (pts_rt % 60).ToString().PadLeft(2, '0');

                    dr_nv["tt"] = tt.ToString();
                    dr_nv["tn"] = tn.ToString();
                    dr_nv["tl"] = tl.ToString();
                    dr_nv["ht"] = ht.ToString();
                    dr_nv["hn"] = hn.ToString();
                    dr_nv["m4"] = m1.ToString();
                    dr_nv["m5"] = m2.ToString();
                    dr_nv["m6"] = m3.ToString();
                    if (kq1 > 0 && kq2 > 0 && kq2 > 0)
                    {
                        sn_tru = (m1 / kq1 * get_muctru("M4")) + (m2 / kq2 * get_muctru("M5")) + (m3 / kq3 * get_muctru("M6"));
                    }
                    dr_nv["sntru_tt"] = sn_tru.ToString();
                    dr_nv["hl"] = hl.ToString();
                    //i++;
                    }
                ds_nv.WriteXml("..\\xml\\h_Bangchamcong_thuongtrucvt.xml", XmlWriteMode.WriteSchema);
                if (ds_nv.Tables[0].Rows.Count > 0)
                {
                    frmReport f = new frmReport(mDB, ds_nv, "", "h_Bangchamcong_thuongtrucvt.rpt", true, 0,user_dn);
                    f.ShowDialog();
                }
                    
            }
            else MessageBox.Show("Không có dữ liệu!");
        }
        private decimal get_muctru(string kyhieu)
        {
            decimal muctru = 0;
            if (ds_dmqd.Tables[0].Rows.Count > 0)
            {
                DataRow[] dr = ds_dmqd.Tables[0].Select("kyhieu='" + kyhieu.Trim() + "'");
                if (dr.Length > 0)
                {
                    muctru = decimal.Parse(dr[0]["songay"].ToString().Trim());
                }
            }
            return muctru;
        }
        private int get_solan(string kyhieu)
        {
            int solan = 0;
            if (ds_dmqd.Tables[0].Rows.Count > 0)
            {
                DataRow[] dr = ds_dmqd.Tables[0].Select("kyhieu='" + kyhieu.Trim() + "'");
                if (dr.Length > 0)
                {
                    solan = int.Parse(dr[0]["solan"].ToString().Trim());
                }
            }
            return solan;
        }
        private int sogio_lv(string thang, string nam)
        {
            int ngay_ct = mDB.cuoituan(thang, nam);// tong so ngay cuoi tuan trong thang (t7+ chu nhat)
            int ngay_t7 = mDB.ngaythu7(thang, nam);// ngay thu 7 trong thang
            int ngay_tt = mDB.ngaytrongthang(thang, nam);// ngay trong thang
            int sogio = (ngay_tt - ngay_ct) * 8 + ngay_t7 * 7;
            return sogio;
        }
        #endregion
        private void btn_xem_Click(object sender, EventArgs e)
        {
            if (!ktra(txtthang.Text.Trim()))
            {
                MessageBox.Show(lan.Change_language_MessageText("Tháng không hợp lệ !"),lan.Change_language_MessageText( "Thông báo"));
                txtthang.Focus();
                return;
            }
            if (!ktra(txtnam.Text.Trim()))
            {
                MessageBox.Show(lan.Change_language_MessageText("Năm không hợp lệ !"),lan.Change_language_MessageText( "Thông báo"));
                txtnam.Focus();
                return;
            }
            thang = txtthang.Text.Trim().PadLeft(2, '0');
            nam = txtnam.Text.Trim();
            if (!mDB.bMmyy(thang + nam.Substring(2, 2)))
            {
                MessageBox.Show(lan.Change_language_MessageText("Số liệu chưa tạo !"),lan.Change_language_MessageText( "Thông báo"));
                return;
            }
            if (bvantay)
            {
                print1();
            }
            else
            {
                print(1);
            }
            btn_xem.Focus();
        }

        private void btn_thoat_Click(object sender, EventArgs e)
        {
            this.Close();
        }

        private void txtthang_Validated(object sender, EventArgs e)
        {
            thang = txtthang.Text.Trim().PadLeft(2, '0');
            nam = txtnam.Text.Trim();
            s_mmyy = thang + nam.Substring(2, 2);
            s_ncuoithang = mDB.get_ncuoithangddmmyyyy(thang,nam);
            DateTime d1 = Convert.ToDateTime(s_ncuoithang.Substring(3, 2) + "/" + s_ncuoithang.Substring(0, 2) + "/" + s_ncuoithang.Substring(6, 4));
            s_mmyy1 = d1.AddMonths(1).ToString("MMyy");
            ngay = mDB.get_ngaytrongthang(thang, nam);
            tungay = "01/" + thang + "/" + nam;
            denngay = ngay + "/" + thang + "/" + nam;
            bvantay = mDB.bVantay(s_mmyy);
            ds_ngayle = mDB.get_ngaynghile(0, s_mmyy);
            ds_ngaybule = mDB.get_ngaynghile(1, s_mmyy);
        }

        private void txtnam_Validated(object sender, EventArgs e)
        {
            thang = txtthang.Text.Trim().PadLeft(2, '0');
            nam = txtnam.Text.Trim();
            s_mmyy = thang + nam.Substring(2, 2);
            s_ncuoithang = mDB.get_ncuoithangddmmyyyy(thang,nam);
            DateTime d1 = Convert.ToDateTime(s_ncuoithang.Substring(3, 2) + "/" + s_ncuoithang.Substring(0, 2) + "/" + s_ncuoithang.Substring(6, 4));
            s_mmyy1 = d1.AddMonths(1).ToString("MMyy");
            ngay = mDB.get_ngaytrongthang(thang, nam);
            tungay = "01/" + thang + "/" + nam;
            denngay = ngay + "/" + thang + "/" + nam;
            bvantay = mDB.bVantay(s_mmyy);
            ds_ngayle = mDB.get_ngaynghile(0, s_mmyy);
            ds_ngaybule = mDB.get_ngaynghile(1, s_mmyy);
        }

        private void cbobophan_SelectedIndexChanged(object sender, EventArgs e)
        {
            if (this.ActiveControl == cbobophan)
            {
                if (cbobophan.SelectedIndex != -1)
                {
                    s_bophan = cbobophan.SelectedValue.ToString();
                    bvantay = mDB.bVantay(s_mmyy);
                }
            }
        }
        private void cbobophan_TextChanged(object sender, EventArgs e)
        {
            if (cbobophan.Text == "")
                s_bophan = "";
        }
	}
}
